package com.mycompany.sigemp.repository.hibernate;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.mycompany.sigemp.model.Usuario;
import com.mycompany.sigemp.repository.UsuarioRepository;

@Repository
public class HibernateUsuarioRepository extends HibernateDaoSupport implements UsuarioRepository {
	
	@Autowired
	public HibernateUsuarioRepository(SessionFactory sessionFactory){
		setSessionFactory(sessionFactory);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Usuario validarUsuario(String alias, String clave) {
		List<Usuario> lista = getHibernateTemplate().find("from Usuario where alias='"+alias+"' and clave='"+clave+"'");
		if(lista.size()==0)
			return null;
			return lista.get(0);
	}

}
